package com.zhangzc.sc.scproduct.exception;



import com.zhangzc.sc.sccommon.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
@RestControllerAdvice(basePackages = "com/zhangzc/sc/scproduct/controller")
public class MarkExceptionHandle {

    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    public R exception(MethodArgumentNotValidException e) {
        log.error("数据获取有问题：{},异常的类型是：{}",e.getMessage(), e.getClass());
        BindingResult bindingResult = e.getBindingResult();
        return R.error().put("msg", bindingResult.getFieldError().getDefaultMessage());

    }
}
